/*===========================================
	Paradigm Engine for Twilight Hack
	Build 1.0
	Camera definitions
	
	(C)2008 Vicious1988 - Syndicate Development
===========================================*/

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include <math.h>
#include <ogcsys.h>
#include <gccore.h>
#include "cameras.h"


#define DEFAULT_FIFO_SIZE	(256*1024)
int totalcams=0;
int currentcam;

camera cams[999];

int camera_create ()
{
	cams[totalcams].x=0.0;
	cams[totalcams].y=0.0;
	cams[totalcams].z=150.0;
	
	currentcam=totalcams;
	totalcams++;
	return totalcams-1;
}

void camera_setActive(int target){
	currentcam=target;
}

void camera_setPosition(int target, float x, float y, float z){
	cams[target].x = x;
	cams[target].y = y;
	cams[target].z = z;
}


void camera_setRotation(int target, float rx, float ry, float rz){
	cams[target].rotx=rz;
	cams[target].roty=ry-180;
	cams[target].rotz=rx;
}

void camera_move(int target,float distance){
	float rota=cams[currentcam].roty;
	cams[target].x += (sin(rota*3.14/180))*(distance);
	cams[target].z += (cos(rota*3.14/180))*(distance);
}

void camera_strafe(int target,float distance){
	float rota=cams[currentcam].roty;
	cams[target].x -= (cos(rota*3.14/180))*(distance);
	cams[target].z -= (sin(rota*3.14/180))*(distance);
}

void camera_update(Mtx v){
	float rotx=cams[currentcam].rotx;
	float roty=cams[currentcam].roty;
	float rotz=cams[currentcam].rotz;
	
	float x=cams[currentcam].x;
	float y=cams[currentcam].y;
	float z=cams[currentcam].z;

	Vector cam={ x, y, z };
	Vector up={ 0, 1, 0 };
	Vector look={ x+sin((roty)*3.14/180)*2, 0, z+cos((roty)*3.14/180)*2 };
	//sin((rotx)*3.14/180)*2
	
	guLookAt (v, &cam, &up, &look);
}
